#include "StdAfx.h"
#include <IJobManager_JobDelegator.h>

namespace 
{ 
	static void cryAsyncMemcpy_Int(
		void* dst
		, const void* src
		, size_t size
		, int nFlags
		, volatile int* sync)
	{
		cryMemcpy(dst, src, size, nFlags);
		if (sync) 
			CryInterlockedDecrement(sync);
	}
}

DECLARE_JOB("CryAsyncMemcpy", TCryAsyncMemcpy, cryAsyncMemcpy_Int );

#if !defined(CRY_ASYNC_MEMCPY_DELEGATE_TO_CRYSYSTEM)
CRY_ASYNC_MEMCPY_API void cryAsyncMemcpy(
#else
CRY_ASYNC_MEMCPY_API void _cryAsyncMemcpy(
#endif 
	void* dst
	, const void* src
	, size_t size
	, int nFlags
	, volatile int* sync)
{ 
# if !defined(_RELEASE)
	if (IsPointerFromStack(dst) || IsPointerFromStack(const_cast<void*>(src)))
		CryFatalError("passing pointer pointing to stack range into _cryAsyncMemcpy");
# endif 
	TCryAsyncMemcpy job( dst, src, size, nFlags, sync );
	job.SetCacheMode(JobManager::SPUBackend::eCM_None); 	
	job.Run();			
}



